<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex flex-direction flex-wrap align-stretch benben-position-layout flex addStudy_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between addStudy_fd0_0'>
					<view class='flex flex-wrap align-center addStudy_fd0_0_c0' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">
						<text class='fu-iconfont2  addStudy_fd0_0_c0_c0'>&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-center'>
						<text class='addStudy_fd0_0_c1_c0'>添加课程任务</text>
					</view>
					<view class='flex align-center justify-end addStudy_fd0_0_c0'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<!---flex布局flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout addStudy_flex_1">
				<view class='flex flex-wrap align-center addStudy_fd1_0'>
					<text class='addTask_fd1_0_c0001'>*</text>
					<text class='addStudy_fd1_0_c0'>课程名称</text>
					<benben-input class='flex-sub addStudy_fd1_0_c1' type="text" :placeholder="`请输入课程名称`"
						confirm-type="done" :maxlength="50"
						placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx"
						v-model="courseData.kechengmingcheng" />
				</view>
				<view class='flex flex-wrap align-center addStudy_fd1_0' @tap.stop="pickerDiy1696922829112=true">
					<text class='addTask_fd1_0_c0001'>*</text>
					<text class='addStudy_fd1_0_c0'>课程分类</text>
					<benben-input class='flex-sub addStudy_fd1_0_c1' type="text" :placeholder="`请选择课程分类`"
						confirm-type="done" :maxlength="-1" :disabled='true'
						placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx"
						v-model="courseData.fenleimingcheng" />
				</view>
				<view class="addStudy_fd0_0001">
					<text class='addTask_fd1_0_c0001'>*</text>
					<text class='addStudy_fd1_2'>封面</text>
				</view>
				<view class='flex flex-wrap align-center'>
					<view class="upload position-relative addStudy_fd1_3_c0">
						<image class=" addStudy_fd1_3_c0_image" mode="aspectFill"
							@tap="soloChooseImage('kechengfengmian','kechengfengmian',courseData,courseData)"
							:src="courseData.kechengfengmian ? courseData.kechengfengmian : STATIC_URL+'104.jpg'">
						</image>
					</view>
				</view>
			</view>

			<!---flex布局flex布局结束-->
			<!--课程分类选择器开始 -->
			<benben-picker ref="benbenWritePickerCodepicker2" :visible.sync="pickerDiy1696922829112"
				:label.sync='courseData.fenleimingcheng' :value.sync='courseData.freefenleiguanli_id'
				:options='courseType' mode='selector' :mask-show='true' :timeout='true' :picker-height='88'
				default-type='aid' :default-props='{"label":"fenleimingcheng","value":"aid"}'>
				<template #picker-header>
					<view class='flex flex-wrap align-center justify-between addStudy_picker2_0'>
						<text class='addStudy_picker2_0_c0' @tap="$refs.benbenWritePickerCodepicker2.cancel()">取消</text>
						<text class='addStudy_picker2_0_c1'>请选择</text>
						<text class='addStudy_picker2_0_c2'
							@tap="$refs.benbenWritePickerCodepicker2.pickerConfirm()">确认</text>
					</view>
				</template>
			</benben-picker>
			<!--课程分类选择器结束 -->
			<view class="flex flex-wrap align-start justify-center benben-position-layout flex addStudy_flex_3">
				<button class='addStudy_fd3_0' @tap.stop="postCourseFunc()">提交</button>

			</view>
			<view :style="{height: '120rpx'}"></view>


		</view>
	</view>
</template>
<script>
	import UploadImage from '@/common/utils/upload-image.js'
	import {
		validate
	} from '@/common/utils/validate.js'

	export default {
		components: {},


		data() {
			return {
				"pickerDiy1696922829112": false,
				"courseType": [],
				"courseData": {
					"aid": "",
					"kechengmingcheng": "",
					"kechengfengmian": "",
					"freefenleiguanli_id": "",
					"fenleimingcheng": ""
				},
				"id": "",
				"shopID": ""
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},
			/**
			 * @returns 
			 * Android       安卓
			 * IOS       苹果
			 * Web       H5 或 pc
			 * Wechat       微信小程序
			 * Alipay       支付宝小程序
			 * Baidu       百度小程序
			 * ByteBounce       抖音小程序
			 * 360       360小程序
			 * FastApp       快应用
			 */
			appSystemIdentification() {
				return this.$store.state.appSystemIdentification
			}
		},
		watch: {},
		onLoad(options) {
			let {
				id,
				shopID
			} = options
			if (id !== undefined) this.id = id
			if (shopID !== undefined) this.shopID = shopID
			this.getCourseFunc()
			this.getcourseListFunc()
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//上传单图、多图方法
			soloChooseImage(id, path, obj, obj1, fnName = false) {
				if (!this.setCheckPermission(2)) {
					return
				}
				let self = this
				if (!obj) obj = this
				if (!obj1) obj1 = this
				if (self.uploading) {
					return
				}
				// 从相册中选择图片
				uni.chooseImage({
					count: 1, // 默认3
					sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
					success: function(res) {
						self.uploading = true
						// 开始上传
						new UploadImage(res.tempFiles, {
							complete: function(res) {
								self.uploading = false
								if (id) self.$set(obj, id, res[0].id)
								if (path) self.$set(obj1, path, res[0].path)
								if (fnName) self[fnName]()
							},
						})
					},
				})
			},
			//获取课程分类
			async getCourseFunc() {
				//请求方法
				//数据验证

				let datacourseType = await this.$api.get(global.apiUrls.post6524fd00347c0, {

				});

				if (datacourseType.data.code != 1) {
					this.$message.info(datacourseType.data.msg);
					return
				}
				let infocourseType = datacourseType.data;
				this.courseType = infocourseType.data

			},
			//提交课程
			async postCourseFunc() {
				if (!validate(this.courseData.kechengmingcheng, 'require')) {
					this.$message.info('请输入课程名称');
					return false;
				}
				if (!validate(this.courseData.freefenleiguanli_id, 'require')) {
					this.$message.info('请选择课程分类');
					return false;
				}
				if (!validate(this.courseData.kechengfengmian, 'require')) {
					this.$message.info('请上传课程封面');
					return false;
				}
				//请求方法
				//数据验证

				let data6524f82d9fabf = await this.$api.dbPost(global.apiUrls.post6524f82d9fabf, {
					aid: this.id,
					kechengmingcheng: this.courseData.kechengmingcheng,
					usermerchant_id: this.shopID,
					kechengfengmian: this.courseData.kechengfengmian,
					freefenleiguanli_id: this.courseData.freefenleiguanli_id
				});
				if (!data6524f82d9fabf) return
				if (data6524f82d9fabf.data.code != 1) {
					this.$message.info(data6524f82d9fabf.data.msg);
					return
				}



				if (this.id == '') {
					this.$message.info('添加成功');
					setTimeout(() => {
						this.$urouter.navigateBack(1);
					}, 500)
				} else {
					this.$message.info('修改成功');
					setTimeout(() => {
						this.$urouter.navigateBack(1);
					}, 500)
				}
			},
			//获取课程信息
			async getcourseListFunc() {
				//请求方法
				//数据验证

				let datacourseData = await this.$api.get(global.apiUrls.post6524fff80c857, {
					aid: this.id
				});

				if (datacourseData.data.code != 1) {
					this.$message.info(datacourseData.data.msg);
					return
				}
				let infocourseData = datacourseData.data;
				this.courseData = infocourseData.data

			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: var(--benbenbgColor1);
		background-size: 100% auto;
	}

	.addStudy_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.addStudy_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
	}

	.addStudy_fd0_0_c0_c0 {
		font-size: 36rpx;
		color: #333;
		font-weight: 500;
	}

	.addStudy_fd0_0_c0 {
		width: 100rpx;
	}

	.addStudy_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		line-height: 88rpx;
	}

	.addStudy_flex_1 {
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.addStudy_fd1_3_c0_image {
		width: 200rpx;
		height: 200rpx;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	.addStudy_fd1_3_c0 {
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	.addStudy_fd1_2 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		line-height: 40rpx;
		margin: 32rpx 0rpx 32rpx 0rpx;
	}

	.addStudy_fd1_0_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.addStudy_fd1_0_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		line-height: 40rpx;
	}

	.addStudy_fd1_0 {
		border-bottom: 1px solid #eee;
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	.addStudy_picker2_0_c2 {
		color: #4781f5;
		font-size: 32rpx;
		font-weight: 400;
		line-height: 40rpx;
	}

	.addStudy_picker2_0_c1 {
		font-size: 36rpx;
		font-weight: 400;
		color: #333;
		line-height: 50rpx;
	}

	.addStudy_picker2_0_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		line-height: 40rpx;
	}

	.addStudy_picker2_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
		border-radius: 25rpx 25rpx 0rpx 0rpx;
		background-size: 100% auto !important;
		height: 110rpx;
	}

	.addStudy_flex_3 {
		width: 750rpx;
		height: 120rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
	}

	.addStudy_fd3_0 {
		background: #E31D1A;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 32rpx;
		color: #fff;
		width: 686rpx;
		height: 88rpx;
		line-height: 88rpx;
	}

	.addTask_fd1_0_c0001 {
		font-size: 32rpx;
		font-weight: 400;
		color: rgba(227, 29, 26, 1);
		line-height: 40rpx;
		margin-right: 10rpx;
		// margin-top: 10rpx;
	}

	.addStudy_fd0_0001 {
		margin: 32rpx 0 32rpx 0;
	}
</style>